package scene.shape.materials;

import raytracing.HitRecord;
import raytracing.Ray;
import scene.Scene;
import scene.lighting.Light;
import util.Color3f;
import util.Vector3f;

public class SpecularMaterial extends Material{
	
	
	
	private Color3f specularColor;

	public SpecularMaterial(Color3f color, String name, Color3f specularColor) {
		super(color, name);
		this.specularColor = specularColor;
	}
	
	public Color3f shade(HitRecord hr,Light light, int recursiondepth){
		if(recursiondepth > MAX_RECURSIONDEPTH)
			return new Color3f(0,0,0);
 		Vector3f d = hr.getRay().getDirection(),
				 n = hr.getNormal(),
				 r = d.subtract(n.scale(2f*d.dot(n)));
 		Color3f c = getDiffuseShading(hr);
		Ray reflectionRay = new Ray(hr.getIntersectionPoint(), hr.getIntersectionPoint().add(r));
		return c.add(Scene.getInstance().color(reflectionRay, 0 + Scene.EPSILON, Float.POSITIVE_INFINITY, recursiondepth + 1).multiply(specularColor));
	}
	
	public boolean isLightingDependent(){
		return true;
	}
}
